var express = require('express');
var utils = require("../lib/Utils");
var user = require('../controller/UserController');
var main = require('../controller/MainController');
var wechat = require('../controller/WeChatController');
var util = require('../controller/UtilController');
var prod = require('../controller/ProdController');
var sys = require('../controller/SysController');
var order = require('../controller/OrderController');
var customer = require('../controller/CustController');
var router = express.Router();

/* GET home page. */
router.use('/:class/:func', function (req, res, next) {
// router.use('/index', function(req, res, next) {
    console.log('URI /' + req.params.class + '/' + req.params.func);
    req.session.proName = "manager";

    try {
        switch (req.params.class) {
            case 'user' :
                user[req.params.func](req, res, next);
                break;
            case 'main':
                main[req.params.func](req, res, next);
                break;
            case 'wechat':
                wechat[req.params.func](req, res, next);
                break;
            case 'prod':
                prod[req.params.func](req, res, next);
                break;
            case 'util':
                util[req.params.func](req, res, next);
                break;
            case 'sys':
                sys[req.params.func](req,res,next);
                break;
            case 'order':
                order[req.params.func](req,res,next);
                break;
            case 'customer':
                customer[req.params.func](req,res,next);
                break;
            default:
                utils.render(req,res,'login',{});
        }
    } catch (err) {
        console.error(err);
        utils.render(req,res,'login',{});
    }
});

module.exports = router;
